apiready = function(){
seajs.use(['../../V',"../../api","../../jquery","../../app","../../service"],function(V,$api,$,app,service){
	var vm = {
		el: '.container',
	  	data: {
	    	orderList: [],
				page: 1,
				shopId: '',
				tem_order_id: '',
				refundPrice:'',
				order_return_id: '',
				searchName: '',
	  	},
	  	mounted:function() {
				$("#search-input").val(this.searchName);
	  	},
	  	methods:{
				//--返回
				close: function(){
					api.sendEvent({
					    name: 'close_win_refresh',
					    extra: {
					        shopId: api.pageParam.shopId,
					    }
					});

					api.closeWin();
				},
				doSearch: function(){
					this.searchName = $("#search-input").val();
					var scrolltobottom = 0;
					this.orderListGet(scrolltobottom);
				},
				//--获取订单列表
				orderListGet: function(scrolltobottom){
					// var shopId = api.pageParam.shopId; // 商店id
					var unionid = $api.getStorage("shop_unionid"); // 用户id
					var that = this;

					app.ajax(service['orderListGet'],
					{
						data: {
							values: {
								unionid: unionid,
								page: this.page,
								search: this.searchName
							}
						}
					},
					function (res) {
						if(res.code){
							alert("错误代码code："+res.code+"\n错误信息："+res.message)
						}else{
							if(res.data != ''){
								console.log("数据："+JSON.stringify(res.data));
								if(!scrolltobottom){
									that.orderList = [];
								}
								that.orderList = that.orderList.concat(res.data.list);
								// console.log(JSON.stringify("数据："+res.data.list+"类型："+res.data.list.constructor+"长度："+res.data.list.length));

								if(res.data.list.length>0){
									$(".shop_order_null").css("display","none");
									$(".shop_order_list").css("display","block");
								}else{
									if(!scrolltobottom){
										$(".shop_order_null").css("display","block");
										api.toast({
												msg: '没有任何订单',
												duration: 2000,
												location: 'middle'
										});
									}else{
										if(that.page != 1){
											that.page = parseInt(that.page - 1);
											api.toast({
													msg: '没有更多数据...',
													duration: 2000,
													location: 'middle'
											});
										}
									}

								}
								// console.log(that.orderList.constructor);
								console.log("获取商品列表成功!");

							}else if(res.data == ''){
									that.orderList = [];
									api.toast({
										msg: '没有任何订单',
										duration: 2000,
										location: 'middle'
									});
							}


						}
					});
				},
				//--订单详情
				getOrderDetail: function(order_id){
					app.openWin('shopOrderDetail', {order_id: order_id, shopId: this.shopId});
				},
	  		//--底下按钮点击
	  		orderModBtn: function(mod, order_id, user_info){
					var that = this;
					var unionid = $api.getStorage('shop_unionid');

	  			switch(mod){
	  				case "shopChat":
	  					console.log(JSON.stringify(user_info));
							app.openWin('shopChat',{
								otherId: user_info.openid, //id
								nickname: user_info.nickname, //昵称
								src: user_info.avater, //头像
								new_nickname: user_info.new_nickname, //备注
								openid2: user_info.openid
							},{
								reload: true,
							});
	  					break;
	  				case "shopSend":
							//--发货
	  					app.openWin('shopSend', {shopId: that.shopId, order_id: order_id});
	  					break;
	  				case "shopDel":
							//--确认是否删除订单
							$('.tc_box').css("display", "block");
							that.tem_order_id = order_id;
	  					break;
	  				case "shopFlow":
							//--查看物流
	  					app.openWin('shopFlow', {shopId: that.shopId, order_id: order_id});
	  					break;
						case "shopRefundRefuse":
							//--商家拒绝退款
	  					app.openWin('shopRefundRefuse', {shopId: that.shopId, order_id: order_id});
	  					break;
						case "shopRefundPass":
							//--获取退款金额
							app.ajax(service['orderDetailGet'],
							{
								data: {
									values: {
										unionid: unionid,
										order_id: order_id
									}
								}
							},
							function (res) {
								if(res.code){
									alert("错误代码code："+res.code+"\n错误信息："+res.message)
								}else{
									console.log("获取订单详情成功");
									console.log(JSON.stringify(res.data));
									that.refundPrice = res.data.refund.price;
									that.order_return_id = res.data.refund.order_return_id;
									//--商家确认退款提示框
			  					$('.shop_order_refund').css("display", "block");
								}
							});
	  					break;
						case "shopReturnRefuse":
							//--商家拒绝退货
	  					app.openWin('shopReturnRefuse', {shopId: that.shopId, order_id: order_id});
	  					break;
						case "shopReturnPass":
							//--获取退款金额
							app.ajax(service['orderDetailGet'],
							{
								data: {
									values: {
										unionid: unionid,
										order_id: order_id
									}
								}
							},
							function (res) {
								if(res.code){
									alert("错误代码code："+res.code+"\n错误信息："+res.message)
								}else{
									console.log("获取订单详情成功");
									console.log(JSON.stringify(res.data));
									that.refundPrice = res.data.refund.price;
									that.order_return_id = res.data.refund.order_return_id;
									// --商家确认退货提示框
									$('.shop_order_return').css("display", "block");
								}
							});

	  					break;
	  				default:
	  					break;
	  			}
				},
				//--取消删除订单
				delOrderCancel: function(et){
					$('.tc_box').css("display", "none");
				},
				//--确定删除订单
				delOrderSure: function(){
					var that = this;
					var unionid = $api.getStorage('shop_unionid');


					app.ajax(service['shopDelOrder'],
					{
						data: {
							values: {
								unionid: unionid,
								order_id: that.tem_order_id
							}
						}
					},
					function (res) {
						if(res.code){
							alert("错误代码code："+res.code+"\n错误信息："+res.message)
						}else{
							console.log(res.data);
							api.toast({
									msg: '订单已删除',
									duration: 2000,
									location: 'middle'
							});
							that.tem_order_id = '';
							$('.tc_box').css("display", "none");
							var scrolltobottom = 0;
							that.orderListGet(scrolltobottom);
						}
					});
				},
				//------------------------------------
				//--关闭确认退款确认框(点击模态框事件)
				close_shop_order_refund: function(){
					$('.shop_order_refund').css("display", "none");
				},
				//--关闭确认退款确认框(点击取消按钮)
				closeRefund: function(){
					$('.shop_order_refund').css("display", "none");
				},
				//--确认退款事件
				passRefund: function(){
					var that = this;

					var unionid = $api.getStorage('shop_unionid');
					var order_return_id = this.order_return_id;

					app.ajax(service['agreeReturnOrder'],
					{
						data: {
							values: {
								unionid: unionid,
								order_return_id: order_return_id
							}
						}
					},
					function (res) {
						if(res.code){
							alert("错误代码code："+res.code+"\n错误信息："+res.message)
						}else{
							console.log("确认退款成功");
							console.log(JSON.stringify(res.data));
							//--关闭确认退款提示框
							$('.shop_order_refund').css("display", "none");

							var scrolltobottom = 0;
							that.orderListGet(scrolltobottom);
						}
					});
				},
				//------------------------------------
				//--关闭确认退货确认框(点击模态框事件)
				close_shop_order_return: function(){
					$('.shop_order_return').css("display", "none");
				},
				//--关闭确认退货确认框(点击取消按钮)
				closeReturn: function(){
					$('.shop_order_return').css("display", "none");
				},
				//--确认退货事件
				passReturn: function(){
					var that = this;

					var unionid = $api.getStorage('shop_unionid');
					var order_return_id = this.order_return_id;

					app.ajax(service['agreeReturnOrder'],
					{
						data: {
							values: {
								unionid: unionid,
								order_return_id: order_return_id
							}
						}
					},
					function (res) {
						if(res.code){
							alert("错误代码code："+res.code+"\n错误信息："+res.message)
						}else{
							console.log("确认退货成功");
							console.log(JSON.stringify(res.data));
							//--关闭确认退货提示框
							$('.shop_order_return').css("display", "none");

							var scrolltobottom = 0;
							that.orderListGet(scrolltobottom);
						}
					});
				},
				// 触底
				scrolltobottom: function () {
					var that = this;
					this.page = parseInt(this.page + 1);
					var scrolltobottom = 1;

					this.orderListGet(scrolltobottom);
				}
	  	},
	  	created: function(){
				var that = this;
				this.shopId = api.pageParam.shopId;
				this.searchName = api.pageParam.searchName;
				var unionid = $api.getStorage("shop_unionid"); // 用户id

				this.page = 1;
				//获取分类后的商品列表
				var scrolltobottom = 0;
				this.orderListGet(scrolltobottom)


				api.addEventListener({
						name: 'close_win_refresh',
				}, function(ret, err){
						that.shopId = ret.value.shopId;
						var scrolltobottom = 0;
						that.orderListGet(scrolltobottom);
						// vue.getTradingMoney();
				});

				api.addEventListener({
			 	    name: 'scrolltobottom',
						extra:{
				        threshold:0            //设置距离底部多少距离时触发，默认值为0，数字类型
				    }
			 	}, function(ret, err){
						that.scrolltobottom()
			 	});
	  	}
	};

	var even = function() {}
	var newVue = new Vue(vm);
	even();
});
}
